#pragma once
#include <iomanip>
#include <sstream>
#include <iostream>
#include "common.h"
#include "tostring.h"
using namespace std;

class sstream : public stringstream
{
public:
	template<typename T>
	inline sstream& operator=(T v)
	{
		this->str("");
		(*(stringstream*)this) << v;
		return *this;
	}
public:
	template<typename T>
	inline sstream& operator>>(T& v)
	{
		cout << __func__ << str() << endl;
		(*(stringstream*)this) >> v;
		return *this;
	}
};

//operator=
template<> inline sstream& sstream::operator=(char v)
{
	str("");
	(*(stringstream*)this) << (0x0ff & v);
	return *this;
}
template<> inline sstream& sstream::operator=(signed char v)
{
	str("");
	(*(stringstream*)this) << (0x0ff & v);
	return *this;
}
template<> inline sstream& sstream::operator=(unsigned char v)
{
	str("");
	(*(stringstream*)this) << (0x0ff & v);
	return *this;
}

//operator>>
template<> inline sstream& sstream::operator>>(char& v)
{
	int value = 0;
	(*(stringstream*)this) >> value;
	v = value;
	cout << __func__ << (int)value << endl;
	return *this;
}
template<> inline sstream& sstream::operator>>(signed char& v)
{
	int value = 0;
	(*(stringstream*)this) >> value;
	v = value;
	cout << __func__ << (int)v << endl;
	return *this;
}
template<> inline sstream& sstream::operator>>(unsigned char& v)
{
	int value = 0;
	(*(stringstream*)this) >> value;
	v = value;
	cout << __func__ << (int)v << endl;
	return *this;
}
template<> inline sstream& sstream::operator>>(CommonA11& a)
{
	double value = 0.0;
	(*(stringstream*)this) >> value;
	a = value;
	cout << __func__ << std::fixed << std::setprecision(2) << value << endl;
	return *this;
}
template<> inline sstream& sstream::operator>>(CommonA14& a)
{
	double value = 0.0;
	(*(stringstream*)this) >> value;
	a = value;
	cout << __func__ << std::fixed << std::setprecision(2) << value << endl;
	return *this;
}
template<> inline sstream& sstream::operator>>(CommonA15& a)
{
	a = Calendar("%y-%m-%d %H:%M", str());
	cout << __func__ << hexBySize(a) << endl;
	return *this;
}
template<> inline sstream& sstream::operator>>(CommonA17& a)
{
	a = Calendar("%m-%d %H:%M", str());
	cout << __func__ << hexBySize(a) << endl;
	return *this;
}
template<> inline sstream& sstream::operator>>(CommonA20& a)
{
	a = Calendar("%y-%m-%d", str());
	cout << __func__ << hexBySize(a) << endl;
	return *this;
}
template<> inline sstream& sstream::operator>>(CommonA23& a)
{
	double value = 0.0;
	(*(stringstream*)this) >> value;
	a = value;
	cout << __func__ << std::fixed << std::setprecision(2) << value << endl;
	return *this;
}
